﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ThanhTu.GNC.Media.KQXS.DataAccess.DAL;


namespace WebUI.Admin.UserControls
{
    public partial class ResultLotteryList : System.Web.UI.UserControl
    {
        private int pageSize = 5;
        private int pageIndex = 1;
        private int rowCount = 0;
        protected void Page_Init(object sender, EventArgs e)
        {

        }

        private void LoadAll()
        {
            ResultLotteryDAL resultLottery = new ResultLotteryDAL();
            int rowCount = 0;
            int pageIndex = 1;
            try
            {
                pageIndex = int.Parse(Request.QueryString["p"].ToString());
            }
            catch { }

            DataTable dt = resultLottery.SelectAll_KQ_User(pageIndex, 5, ref rowCount);
            RepeaterResultLotteryList.DataSource = dt;
            lblTotal.Text = rowCount.ToString();
            RepeaterResultLotteryList.DataBind();
            int numberPage = (rowCount%5==0)?rowCount/5:(rowCount/5+1);
            NHPagingControl1.TotalPage = numberPage;
            

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadAll();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("AddNewResultData.aspx");
        }

        protected void RepeaterResultLotteryList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ResultLotteryDAL resultLotteryDAL = new ResultLotteryDAL();
                int checkDEL = resultLotteryDAL.DeleteLottery(e.CommandArgument.ToString(), Convert.ToDateTime(e.CommandName.ToString()));
                if (checkDEL > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('XÓA bản ghi  Thành công);", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('LỖI XÓA ,XIN VUI LÒNG THỬ LẠI);", true);
                }
            }
        }




    }
}